<template>
    <el-tree-select v-model="modelValue" :data="categoryData" :render-after-expand="false" style="width: 250px"
        :default-expand-all="true" :check-strictly="strictly" />
</template>
<script lang="ts" setup>
const categoryData = ref<any>([]);

const modelValue = defineModel();
const title = defineModel("title", { default: "一级目录" });
const strictly = defineModel("strictly", { default: true });

onMounted(() => {
    callApi()
})
const callApi = () => {

    //肉食主义者

    categoryApi.select({ status: 1 }).then((cateData: any) => {



        cateData.forEach((item: any) => {
            item.label = item.name
            item.value = item.id
        })

        //把扁平化的数据转成树型结构
        let eatFoods = cateData.reduce((duzi: any, currentValue: any) => {

            currentValue.children = cateData.filter((item: any) => {
                if (item.parentId == currentValue.id) {
                    return item
                }
            })
            if (currentValue.parentId == 0) {

                duzi.push(currentValue)
            }
            return duzi;
        }, [])



        categoryData.value = [{ value: 0, label: title.value }].concat(eatFoods)



    })
}
</script>